package com.my.jvm.task;

import org.springframework.stereotype.Service;

import java.util.HashSet;
import java.util.Set;

/**
 * @author Zijian Liao
 * @since 1.0.0
 */
@Service
public class OrderService {
    
    private static final Set<String> orderSet = new HashSet<>();
    
    public String refundOrder(String orderNo) throws InterruptedException {
        // 判断订单是否已退款
        if(!orderSet.contains(orderNo)){
            // 模拟业务停顿50ms
            Thread.sleep(50L);
            // 检查订单是否重复退款
            if(!orderSet.add(orderNo)){
                return "fail";
            }
        }
        
        return "ok";
    }
}
